package com.ruoyi.merchant.msg.Model;


import com.ruoyi.merchant.msg.requ.AbstractRequMsg;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;

/**
 * 1.登录包 (上行协议号：AP00，响应：BP00)
 */
@Slf4j
@Data
public class AP50 extends AbstractRequMsg {
    /**
     * 数据起封包
     */
    public String headCode = "IW";
    /**
     * 协议号
     */
    public final  String funCode = "AP50";
    /**
     * 体温
     */
    private BigDecimal temperature;
    /**
     * 电量
     */
    private Integer power;
    /**
     * 结尾封包
     */
    public String footCode = "#";


     public AP50(){}

    /**
     * IWAP50,36.7,90#
     * @param cmdStr
     */
    public AP50(String cmdStr)
    {
        String[] split = cmdStr.split(",");
        if (cmdStr.startsWith("IWAP50"))
        {
            this.temperature = new BigDecimal(split[1].toString());
            if (!split[2].equals("#")){
                this.power = Integer.valueOf(split[2].replace("#",""));
            }
        }
        else {
            log.error("协议格式错误:{}",cmdStr);
        }

    }



}
        



